package com.fzkj.juc.spinlock;

import java.util.concurrent.TimeUnit;

/**
 * @DESCRIPTION 自己写的自旋锁测试
 */
public class SpinLockDemo {

    public static void main(String[] args) {
        SpinLock spinLock = new SpinLock();
        new Thread(() -> {
            spinLock.lock();
            test("BBB");
            spinLock.unLock();
        }, "BBB").start();

        new Thread(() -> {
            spinLock.lock();
            test("AAA");
            spinLock.unLock();
        }, "AAA").start();
    }

    public static void test(String name){
        System.out.println(name + "\t 进行业务操作中...");
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
